package com.wootion.cims.general.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.Calendar;

public class IdChack {
	static Calendar c=Calendar.getInstance();
	public static JSONObject IDcard(String IDcard) {
		switch(IDcard.length()) {
			case 18:
			case 16:
				String year = IDcard.substring(6, 10);
				if(Integer.decode(year) <1900 && Integer.decode(year)>c.get(Calendar.YEAR))
					return null;
				String month = IDcard.substring(10,12);
				String day = IDcard.substring(12,14);

				if (month.indexOf("0") != -1){
					month = month.substring(1,2);
				}
				if (day.indexOf("0") != -1 && day.indexOf("0") != 1){
					day = day.substring(1,2);
				}
				if (!month.equals("08") || !month.equals("09")){
					if(Integer.decode(month)<1 && Integer.decode(month)>12)
						return null;
				}
				c.set(Integer.decode(year) ,Integer.decode(month), 0);
				if(Integer.decode(day)>c.get(Calendar.DAY_OF_MONTH))
					return null;

//				System.out.println("尊贵的用户，您的生日为："+year+"年"+month+"月"+day+"日");
				JSONObject object = new JSONObject();
				if (Integer.decode(month) < 10){
					month = "0"+month;
				}
				if (Integer.decode(day) < 10){
					day = "0"+day;
				}
				object.put("year",year);
				object.put("month",month);
				object.put("day",day);
				return object;
			default:
				return null;
		}
	}
}
